﻿import ShowFormItem from './FormItemComponents.vue'
export default {
  props: ['pageFormInfo', 'models', 'rules', 'changeModels', 'dynamicUid', 'dialogType', 'pageRow', 'fatherName', 'pPageRow'],
  data () {
    return {
      formLayoutModels: {}
    }
  },
  created () {
    this.getModelsKeyAndValue()
  },
  methods: {
    // 获取models中的键和值
    getModelsKeyAndValue () {
      if (!this.$isEmptyObject(this.models)) {
        for (let key in this.models) {
          this.$set(this.formLayoutModels, key, this.models[key])
        }
      } else {
        this.formLayoutModels = {}
      }
    },
    // 验证表单的方法
    validateFormMethod () {
      let isValidate = false
      this.getModelsKeyAndValue()
      this.$refs['dynamicMenuShow'].validate((valid) => {
        isValidate = valid
      })
      return isValidate
    },
    // 取消表单验证
    resetValidate () {
      this.getModelsKeyAndValue()
      this.$refs['dynamicMenuShow'].resetFields()
    },
    // 获取表单的数据(提交表单时)
    getFormData (fromFormItem) {
      this.$emit('getFormData', fromFormItem)
    },
    // 按钮直接执行事件
    triggerSelfdefineEvent (fromFormItem) {
      this.$emit('triggerSelfdefineEvent', fromFormItem)
    },
    // 取消表单提交时
    resetFormData () {
      this.$emit('resetFormData')
    },
    // 处理行事件时
    handelRowEvents (fromFormItem) {
      this.$emit('handelRowEvents', fromFormItem)
    },
    // 打开关联的页面
    openDialog (fromFormItem) {
      this.$emit('openDialog', fromFormItem)
    },
    // 关闭关联的页面时(需要刷新页面)
    closeDynamicMenuDialogSuccess () {
      this.$refs['dynamicMenuShow'].resetFields()
      this.$emit('closeDynamicMenuDialogSuccess')
    },
    itemHadChangeModels (fromFormItem) {
      this.$emit('update:models', fromFormItem)
    },
    // 联动元素触发，改变关联元素的值，需要修改父组件中changeModels值，已更新子组件的数据
    modelsChangedByLinkage (fromFormItem) {
      this.$emit('update:models', fromFormItem)
      this.$emit('update:changeModels', !this.changeModels)
    },
    // 刷新当前页面
    reloadCurrentPage () {
      this.$emit('reloadCurrentPage')
    }
  },
  components: {
    ShowFormItem
  },
  watch: {
    // 当页面初始化时，需要更新页面的数据
    changeModels: {
      handler: function (val) {
        this.getModelsKeyAndValue()
      },
      deep: true
    }
  }
}
